package com.alpaak.common.job;

import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.scheduling.quartz.SpringBeanJobFactory;
import org.springframework.stereotype.Component;

/**
 * @desp job工厂，定时任务
 * @author Zhangdanli
 * @datetime 2018年8月1日19:51:06
 */
@Component("customJobFactory")
public class CustomJobFactory extends SpringBeanJobFactory {
	
	@Autowired
	private AutowireCapableBeanFactory beanFactory;
 
	/**
	 * 
	 * 这里覆盖了super的createJobInstance方法，对其创建出来的类再进行autowire。
	 * 
	 */
	@Override
	protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
 
		Object jobInstance = super.createJobInstance(bundle);
 
		beanFactory.autowireBean(jobInstance);
 
		return jobInstance;
 
	}}
